#include <cstddef>
#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;
template <typename Type>
class MyArray
{ public:
    MyArray():size(0),pArr(NULL)
    {
    }

    MyArray ( Type array[],int len) :size(len)
    {
        pArr=new Type[size];
        for(int i=0;i<size;i++)
            pArr[i]=array[i];
    }

     ~MyArray()
     {
         delete [] pArr;
     }

     void print()
     {
         for(int i=0;i<size;i++)
            cout<<pArr[i]<<"\t";
     }
    //自定义拷贝构造函数
     MyArray (const MyArray& other)
     {
         size=other.size;
         pArr=new Type[size]; 
         for(int i=0;i<size;i++)
            pArr[i]=other.pArr[i];
     }
    //重载赋值运算符=
     MyArray& operator=(const MyArray &other)
     {
         if(this!= &other)
         {
             if(pArr!= NULL)
                delete [] pArr;
            size=other.size;
            pArr=new Type[size]; 
            for(int i=0;i<size;i++)
                pArr[i]=other.pArr[i];
         }
         return *this;
     }
    //重载下标运算符[]
    Type& operator[](int index)
    {
        if(index>=0 && index<size)
            return pArr[index];
        else
        {
            cout<<"ERROR:wrong index\n";
            exit(1);
        }
    } 

 private:
    int size;
    Type *pArr;
};

int main()
{
   int a[5]={2,4,6,8,10};
   MyArray<int> arr(a,4);
   arr.print();
   cout<<endl;

   MyArray<int>arr2(arr);
   arr2[2]=-5;
   arr2.print();
   cout<<endl;

    MyArray<int> arr3;
    arr3=arr;
    arr3[0]=99;
    arr3.print();
    cout<<endl;

   char* s[3]={"how","are","you?"};
   MyArray<char*> arr4(s,3);
   arr4.print();
   cout<<endl;
   return 0;
}